package test;

import com.alibaba.nacos.api.naming.NamingService;
import com.xw.echo.core.EchoServerProvider;
import com.xw.echo.core.nacos.NacosRegisterServer;
import com.xw.echo.core.nacos.client.NacosClientManager;
import com.xw.echo.core.service.UserService;
import com.xw.echo.core.service.UserServiceImpl;
import lombok.extern.slf4j.Slf4j;

import java.net.UnknownHostException;
import java.util.HashMap;
@Slf4j
public class ServerCluster {
    public static void main(String[] args) throws UnknownHostException {
        // 创建一个HashMap实例，用于存储服务名称与服务实例的映射
        HashMap<String,Object> map=new HashMap<>();

        // 创建UserService的实例
        UserService userService=new UserServiceImpl();

        // 将UserService实例存入map中，键为UserService的类名
        map.put(UserService.class.getName(),userService);

        // 获取Nacos命名服务实例，参数包括服务器地址、用户名和密码
        NamingService namingService = NacosClientManager.getNamingService("47.97.81.253:8848", "nacos", "Wc233333");

        // 创建NacosRegisterServer实例，用于服务注册
        NacosRegisterServer nacosRegisterServer =new NacosRegisterServer(namingService,"Server");

        // 创建EchoServerProvider实例，指定端口和之前创建的服务实例映射
        EchoServerProvider echoServerProvider=new EchoServerProvider(8000,map);

        // 设置EchoServerProvider的注册服务器为NacosRegisterServer实例
        echoServerProvider.setRegisterServer(nacosRegisterServer);

        // 启动EchoServerProvider实例
        echoServerProvider.start();
    }
}
